package com.example.teachermgt.dao;

import com.example.teachermgt.model.Teacher;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface TeacherDao {

    //用户列表
    @Select("select * from teacher")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "age", column = "age")
    })
    List<Teacher> queryAll();

    //根据id获取teacher
    @Select("select * from teacher where id =#{id}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "age", column = "age")
    })
    Teacher findTeacherById(Long id);

    //根据id修改teacher
    @Update("update teacher set name=#{name},age=#{age} WHERE id = #{id} ")
    int updateTeacher(Teacher teacher);

    //根据id删除用户
    @Delete("delete from teacher where id = #{id}")
    int deleteTeacherById(Long id);

    @Insert("insert into teacher (name, age) values(#{name},#{age})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void saveTeacher(Teacher teacher);
}
